package com.jinzhi.jzweb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.utils.StringUtil;
import com.jinzhi.jzweb.domain.OrderSpecsDO;
import com.jinzhi.jzweb.domain.ProductTypeDO;
import com.jinzhi.jzweb.service.ProductTypeService;
import org.springframework.stereotype.Service;

import com.jinzhi.jzweb.dao.BookConfigDao;
import com.jinzhi.jzweb.domain.BookConfigDO;
import com.jinzhi.jzweb.service.BookConfigService;
import com.jinzhi.common.base.CoreServiceImpl;

/**
 * 
 * <pre>
 * 教材配置表
 * </pre>
 * <small> 2024-09-24 14:27:42 | lance</small>
 */
@Service
public class BookConfigServiceImpl extends CoreServiceImpl<BookConfigDao, BookConfigDO> implements BookConfigService {

    private final ProductTypeService productTypeService;
    public BookConfigServiceImpl(ProductTypeService productTypeService){
        this.productTypeService = productTypeService;
    }

    /**
     * 书籍配置分页列表
     * @param bookConfigDO
     * @return
     */
    @Override
    public Page<BookConfigDO> bookList(BookConfigDO bookConfigDO) {
        Page<BookConfigDO> pageList = this.selectPage(
                new Page<BookConfigDO>(bookConfigDO.getCurrent(), bookConfigDO.getSize()),
                new EntityWrapper<BookConfigDO>()
                        .eq(null != bookConfigDO.getTypeId(), "type_id", bookConfigDO.getTypeId())
                        .like(StringUtil.notEmpty(bookConfigDO.getBookName()), "book_name",bookConfigDO.getBookName())
                        .orderBy("id", false)
        );
        if(!pageList.getRecords().isEmpty() && pageList.getRecords().size()>0){
            pageList.getRecords().forEach(record->{
                //查询商品类型名称
                ProductTypeDO productTypeDO = productTypeService.selectById(record.getTypeId());
                if(null!=productTypeDO){
                    record.setTypeName(productTypeDO.getTypeName());
                }
            });
        }

        return pageList;
    }
}
